package com.swf.seed.txt.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.swf.common.utils.FwsFileUtils;
import com.swf.common.utils.FwsIOUtils;

public class BigFileReader {
	private static ThreadLocal<List> fl = new ThreadLocal<List>();
	private static int num = 1;
	static ExecutorService t = Executors.newFixedThreadPool(num);
	
	 public static void main(String[] args) throws Exception {
		 File dir = new File("D:/a/thread");
		 FwsFileUtils.deleteDir(dir);
		 dir.mkdirs();
		 FwsIOUtils io = FwsIOUtils.getInstance().setAppend(true).setCharst("GBK").setOutPath("d:/a/b.txt");
		 int bufSize = 1024;
		 byte[] bs = new byte[bufSize];
		 BufferedReader buf = new BufferedReader(new FileReader("d:/a/a.txt"));
		 int i=0;
		 List<String> l = new LinkedList<String>();
		 String line;
		 while ((line = buf.readLine() )!= null) {  
			 // 把文件当字符串处理，直接打印做为一个例子。  
			 l.add(line);  
			 ++i;
			 if (i==100000){
				 t.execute(new ThreadLocalThread(l));
				 i=0;
				 l = new LinkedList<String>();
			 }
			 }
		 t.shutdown();
		 }
	 }
